<!doctype html>
<html xml:lang="zh-CN" lang="zh-CN">

<head>
        <link rel="canonical" href="https://v2rayjichang.github.io/news/article-109118.htm" />
    <!--====== Required meta tags ======-->
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>从零开始搭建高可用的k8s集群_在线工具</title>
        <meta name="description" content="一、环境准备 　　使用Hyper-V虚拟机功能搭建三台Centos虚拟机系统，配置好静态IP，分别为k8s-node1(192.168.0.8)，k8s-node2(192.168.0.9)，k8s-" />
        <link rel="icon" href="/assets/website/img/surfboardnode/favicon.ico" type="image/x-icon"/>

    <meta name="author" content="V2ray免费机场 节点订阅中文官网">
    <meta property="og:type" content="article" />
    <meta property="og:url" content="https://v2rayjichang.github.io/news/article-109118.htm" />
    <meta property="og:site_name" content="V2ray免费机场 节点订阅中文官网" />
    <meta property="og:title" content="从零开始搭建高可用的k8s集群_在线工具" />
    <meta property="og:image" content="https://v2rayjichang.github.io/uploads/20240709-1/429658daad74043447777814a12b8f89.webp" />
        <meta property="og:release_date" content="2025-05-01T09:04:17" />
    <meta property="og:updated_time" content="2025-05-01T09:04:17" />
        <meta property="og:description" content="一、环境准备 　　使用Hyper-V虚拟机功能搭建三台Centos虚拟机系统，配置好静态IP，分别为k8s-node1(192.168.0.8)，k8s-node2(192.168.0.9)，k8s-" />
        
    <meta name="applicable-device" content="pc,mobile" />
    <meta name="renderer" content="webkit" />
    <meta name="force-rendering" content="webkit" />
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta name="robots" content="max-image-preview:large" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="从零开始搭建高可用的k8s集群_在线工具">
    <meta name="format-detection" content="telephone=no">

    <link rel="dns-prefetch" href="https:/www.googletagmanager.com">
    <link rel="dns-prefetch" href="https://www.googleadservices.com">
    <link rel="dns-prefetch" href="https://www.google-analytics.com">
    <link rel="dns-prefetch" href="https://pagead2.googlesyndication.com">
    <link rel="dns-prefetch" href="https://cm.g.doubleclick.net">
    
    <!--====== Bootstrap css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/bootstrap.min.css">
    <!--====== Slick css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/slick.css">
    <!--====== Magnific Popup css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/magnific-popup.css">
    <!--====== Line Icons css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/LineIcons.css">
    <!--====== Default css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/default.css">
    <!--====== Style css ======-->
    <link rel="stylesheet" href="/assets/website/css/surfboardnode/style.css">
    <link rel="stylesheet" href="/assets/website/css/G.css" />
    <!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LMZ4WN7LCM"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-LMZ4WN7LCM');
</script>
    <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3332997411212854"
     crossorigin="anonymous"></script>
</head>

<body data-page="detail">
    <!--====== HEADER ONE PART START ======-->
    <header class="header-area">
        <div class="navbar-area navbar-one navbar-transparent">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <nav class="navbar navbar-expand-lg">
                    <a class="navbar-brand" href="/">
                                        <span>
                        V2ray免费机场                    </span>
                                        </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarOne" aria-controls="navbarOne" aria-expanded="false" aria-label="Toggle navigation">
                        <span class="toggler-icon"></span>
                        <span class="toggler-icon"></span>
                        <span class="toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse sub-menu-bar" id="navbarOne">
                        <ul class="navbar-nav m-auto">
                                                        <li class="nav-item">
                                <a href="/">首页</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/free-nodes/">免费节点</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/paid-subscribe/">推荐机场</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/news/">新闻资讯</a>
                            </li>
                                                        <li class="nav-item">
                                <a href="/client.htm">客户端</a>
                            </li>
                                                    </ul>
                    </div>
                </nav> <!-- navbar -->
            </div>
        </div> <!-- row -->
    </div> <!-- container -->
</div>
        <div id="home" class="header-content-area d-flex align-items-center list" style="height:450px;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="header-wrapper">
                            <div class="header-content">
                                <h1 class="header-title">从零开始搭建高可用的k8s集群_在线工具</h1>
                                <p class="text nav">
                                    <a href="/">首页</a> / <a href="/news/">新闻资讯</a> / <span>正文</span>
                                </p>
                            </div> <!-- header content -->
                            <div class="header-image d-none d-lg-block">
                                <div class="image">
                                    <img src="/assets/website/img/surfboardnode/header.png" alt="Header">
                                </div>
                            </div>
                        </div>
                    </div>
                </div> <!-- row -->
            </div> <!-- container -->
            <div class="header-shape">
                <img src="/assets/website/img/surfboardnode/header-shape.svg" alt="shape">
            </div> <!-- header-shape -->
        </div> <!-- header content area -->
    </header>
    <!--====== HEADER ONE PART ENDS ======-->
    <!--====== ABOUT THREE PART START ======-->
    <section id="about" class="about-area pt-70 pb-100">
        <div class="container">
            <div class="row">
                <div class="col-md-9">
                                    <input type="hidden" id="share-website-info" data-name="Clash Node官网订阅站" data-url="https://clashnode.github.io">
                <div class="xcblog-blog-detail xcblog-blog-detail-defined">
                      				  				  				<p><strong>一、环境准备</strong></p> <p>　　使用Hyper-V虚拟机功能搭建三台Centos虚拟机系统，配置好静态IP，分别为k8s-node1(192.168.0.8)，k8s-node2(192.168.0.9)，k8s-node3(192.168.0.10)。系统安装成功后配置root远程登录功能，以便使用ssh客户端工具链接。</p> <p>　　初始化系统设置：</p> <p>　　　　◉分配固定IP ：设置虚拟机固定IP的方式比较多，本方案采用设置虚拟的MAC地址为静态ID，然后在路由器中为MAC分配固定IP。</p> <p>　　　　◉开启SSH远程登录：运行命令"  yum install openssh-server "安装ssh服务端工具，安装完成后运行命令" systemctl enable sshd.service "设置开启自启动, 运行命令" vim /etc/ssh/sshd_config "编辑配置文件，设置如下：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/b31db04bfa18a987c329414a1ffd3661.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p> 　　◉修改IPV6为IPV4：centos默认使用ipv6的方式，我们需要修改为ipv4模式来实现ssh客户端的远程连接，具体方法是 cd到 /etc/sysconfig/network-scripts目录下，vim 编辑 ifcfg-eth1 文件，如图，设置IPV6INIT=no,ONBOOT=yes。</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/576e93b20239349141f5e4d5caff97c0.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>　　◉安装docker环境：完成以上步骤后，重启电脑即可使用ssh工具连接，复制命令" <span class="pln">curl <span class="pun">-<span class="pln">sSL https<span class="pun">:<span class="com">//get.daocloud.io/docker | sh </span></span></span></span></span>" 安装dockers环境。</p> <p>　　◉设置docker开机自启：运行命令" <span class="pln">systemctl enable docker </span>" 将docker加入开机启动项。</p> <p>　　◉配置docker镜像加速器：国内从 DockerHub 拉取镜像有时会遇到困难，此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务，此处以配置阿里云镜像加速器为例，登录https://cr.console.aliyun.com/，选择容器镜像服务-镜像工具-镜像加速器，如图所示，通过在/etc/docker/daemon.json文件中配置registry-mirrors属性来实现该功能：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/41387dcd7b31d063e2512a89297fc232.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>　　◉设置防火墙规则：设置防火墙规则的目的是为了确保集群中的机器能够相互通信，本次集群直接使用命令" systemctl disable firewalld "关闭防火墙。</p> <p>　　◉设置 /proc/sys/net/bridge目录下bridge-nf-call-iptables和bridge-nf-call-ip6tables文件的内容为1，确保的 Linux 节点的 iptables 正确查看桥接流量。</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/7a4c09d280988a560a030545faaca7dd.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>　　◉关闭Linux系统的交换分区：为了保证kubelet的正常运行，必须禁用swap交换分区。window平台上称为虚拟内存。在物理内存不够用时，操作系统会从物理内存中把部分暂时不被使用的数据转移到交换分区，从而为当前运行的程序留出足够的物理内存。运行命令" free -m "结果证明已经开启了交换分区，修改/etc/fstab文件，注释掉加载swap分区的这行记录，重启Linux系统即可。</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/656e425c7a8b49cf990dea8d49d67066.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p><strong>二、安装K8S集群</strong></p> <p>　　完成以上步骤后，就可以进行k8s组件的安装了，我们需要三个必须的组件kubeadm、kubelet 和 kubectl，把他们安装到每台集群的机器上。其中kubeadm是引导我们创建集群的命令；kubelet 是集群中的所有机器上运行的组件，并执行诸如启动 pod 和容器之类的操作；kubectl是与集群对话的命令行工具。读者请注意，kubeadm不会为你安装或管理kubelet和kubectl<code>，</code>因此你需要确保它们与control plane之间版本的匹配，如果不这样做，则存在版本偏差的风险，这可能导致意外的错误行为。</p> <p>　　安装步骤：</p> <p>　　1、配置k8s下载地址信息(配置为阿里云镜像，国外镜像很难下载成功)，运行如下命令。</p> <div class="cnblogs_code"> <pre>cat &lt;&lt;EOF &gt; /etc/yum.repos.d/<span style="color: rgba(0, 0, 0, 1)">kubernetes.repo [kubernetes] name</span>=<span style="color: rgba(0, 0, 0, 1)">Kubernetes baseurl</span>=https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/</span> enabled=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)"> gpgcheck</span>=<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> repo_gpgcheck</span>=<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> gpgkey</span>=https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg</span> exclude=<span style="color: rgba(0, 0, 0, 1)">kubelet kubeadm kubectl EOF</span></pre> </div> <p>　　2、运行如下命令安装三个组件。</p> <div class="cnblogs_code"> <pre>yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes</pre> </div> <p>　　3、设置kubelet的开机自启动：启动后kubelet会每隔几秒启动一次来探测kubeadm的命令。</p> <div class="cnblogs_code"> <p>  systemctl enable kubelet &amp;&amp; systemctl start kubelet</p> </div> <p>　　4、提前准备k8s集群必须的组件：在后续的kubeadm init命令中，他需要下载一些必须镜像，这些镜像可以通过 " kubeadm config images list "命令来查看，如图：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/a1b91410efb21dc130d18eee6a59391c.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p> 但是这些镜像默认是从国外源，在国内无法下载，因此有必要在此之前先使用国内源下载好这些镜像，此处使用阿里云镜像地址下载：</p> <div class="cnblogs_code"> <pre>docker pull  registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/coredns:v1.<span style="color: rgba(128, 0, 128, 1)">8.6</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/etcd:<span style="color: rgba(128, 0, 128, 1)">3.5</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>-<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> docker pull  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/pause:<span style="color: rgba(128, 0, 128, 1)">3.6</span></pre> </div> <p>根据上面的命令把镜像都下载完成后，进行镜像复制，调用 "  docker tag  oldimages newimages "命令复制出满足kubeadm init的标准镜像，代码如下：</p> <div class="cnblogs_code"> <pre>docker tag  registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span>          k8s.gcr.io/kube-apiserver:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)">  docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span>              k8s.gcr.io/kube-proxy:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)">  docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span> k8s.gcr.io/kube-controller-manager:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span>          k8s.gcr.io/kube-scheduler:v1.<span style="color: rgba(128, 0, 128, 1)">23.6</span><span style="color: rgba(0, 0, 0, 1)"> docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/coredns:v1.<span style="color: rgba(128, 0, 128, 1)">8.6</span>                  k8s.gcr.io/coredns/coredns:v1.<span style="color: rgba(128, 0, 128, 1)">8.6</span><span style="color: rgba(0, 0, 0, 1)"> docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/etcd:<span style="color: rgba(128, 0, 128, 1)">3.5</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>-<span style="color: rgba(128, 0, 128, 1)">0</span>                   k8s.gcr.io/etcd:<span style="color: rgba(128, 0, 128, 1)">3.5</span>.<span style="color: rgba(128, 0, 128, 1)">1</span>-<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> docker tag  registry.cn</span>-hangzhou.aliyuncs.com/google_containers/pause:<span style="color: rgba(128, 0, 128, 1)">3.6</span>                       k8s.gcr.io/pause:<span style="color: rgba(128, 0, 128, 1)">3.6</span></pre> </div> <p>执行完成所有复制命令后，docker images查看镜像，发现需要的镜像已准备好，列表如下：</p> <p> <img decoding="async" src="http://img.555519.xyz/uploads3/20220501/53f9a8a8b8fa46d9d4c76684479efef1.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>　　5、使用kubeadm来引导我们创建集群。首先运行 " kubeadm init  [arg]"命令，会进行一系列预检查以确保机器已准备好运行 Kubernetes。这些预检查会显示警告并在错误时退出(遇到错误时需要根据具体输出日志解决错误)。然后下载并安装集群控制平面组件。 kubeadm init 包含一些指定参数，其参数说明下：</p> <div class="cnblogs_code"> <pre>      --apiserver-advertise-address <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">   设置 apiserver 绑定的 IP.       </span>--apiserver-bind-port int32            设置apiserver 监听的端口. (默认 <span style="color: rgba(128, 0, 128, 1)">6443</span><span style="color: rgba(0, 0, 0, 1)">)       </span>--control-plane-endpoint <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">        设置控制平面的端点(matser控制节点的IP或域名)       </span>--apiserver-cert-extra-<span style="color: rgba(0, 0, 0, 1)">sans strings    api证书中指定额外的Subject Alternative Names (SANs) 可以是IP 也可以是DNS名称。 证书是和SAN绑定的。       </span>--cert-dir <span style="color: rgba(0, 0, 255, 1)">string</span>                      证书存放的目录 (默认 <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">/etc/kubernetes/pki</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">)       </span>--certificate-key <span style="color: rgba(0, 0, 255, 1)">string</span>                kubeadm-cert secret 中 用于加密 control-<span style="color: rgba(0, 0, 0, 1)">plane 证书的key       </span>--config <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">                         kubeadm 配置文件的路径.       </span>--cri-socket <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">                    CRI socket 文件路径，如果为空 kubeadm 将自动发现相关的socket文件; 只有当机器中存在多个 CRI  socket 或者 存在非标准 CRI socket 时才指定.       </span>--dry-<span style="color: rgba(0, 0, 0, 1)">run                              测试，并不真正执行;输出运行后的结果.       </span>--feature-gates <span style="color: rgba(0, 0, 255, 1)">string</span>                 指定启用哪些额外的feature 使用 key=<span style="color: rgba(0, 0, 0, 1)">value 对的形式。       </span>--help  -<span style="color: rgba(0, 0, 0, 1)">h                             帮助文档       </span>--ignore-preflight-errors strings       忽略前置检查错误，被忽略的错误将被显示为警告. 例子: <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">IsPrivilegedUser,Swap</span><span style="color: rgba(128, 0, 0, 1)">'</span>. Value <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">all</span><span style="color: rgba(128, 0, 0, 1)">'</span> ignores errors <span style="color: rgba(0, 0, 255, 1)">from</span><span style="color: rgba(0, 0, 0, 1)"> all checks.       </span>--image-repository <span style="color: rgba(0, 0, 255, 1)">string</span>              选择拉取 control plane images 的镜像repo (<span style="color: rgba(0, 0, 255, 1)">default</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">k8s.gcr.io</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">) ，国内一般无法直接从k8s.gcr.io获取，需要改为国内的代理地址       </span>--kubernetes-version <span style="color: rgba(0, 0, 255, 1)">string</span>            选择K8S版本. (<span style="color: rgba(0, 0, 255, 1)">default</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">stable-1</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">)       </span>--node-name <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">                     指定node的名称，默认使用 node 的 hostname.       </span>--pod-network-cidr <span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)">              指定 pod 的网络， control plane 会自动将 网络发布到其他节点的node，让其上启动的容器使用此网络       </span>--service-cidr <span style="color: rgba(0, 0, 255, 1)">string</span>                  指定service 的IP 范围. (<span style="color: rgba(0, 0, 255, 1)">default</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">10.96.0.0/12</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">)，不能与机器的IP段有重叠       </span>--service-dns-domain <span style="color: rgba(0, 0, 255, 1)">string</span>            指定 service 的 dns 后缀, e.g. <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">myorg.internal</span><span style="color: rgba(128, 0, 0, 1)">"</span>. (<span style="color: rgba(0, 0, 255, 1)">default</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">cluster.local</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">)       </span>--skip-certificate-key-print            不打印 control-<span style="color: rgba(0, 0, 0, 1)">plane 用于加密证书的key.       </span>--skip-<span style="color: rgba(0, 0, 0, 1)">phases strings                  跳过指定的阶段（phase）       </span>--skip-token-print                     不打印 kubeadm init 生成的 <span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> bootstrap token        </span>--token <span style="color: rgba(0, 0, 255, 1)">string</span>                         指定 node 和control plane 之间，简历双向认证的token ，格式为 [a-z0-<span style="color: rgba(128, 0, 128, 1)">9</span>]{<span style="color: rgba(128, 0, 128, 1)">6</span>}\.[a-z0-<span style="color: rgba(128, 0, 128, 1)">9</span>]{<span style="color: rgba(128, 0, 128, 1)">16</span>} -<span style="color: rgba(0, 0, 0, 1)"> e.g. abcdef.0123456789abcdef       </span>--token-ttl duration                   token 自动删除的时间间隔。 (e.g. 1s, 2m, 3h). 如果设置为 <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">0</span><span style="color: rgba(128, 0, 0, 1)">'</span>, token 永不过期 (<span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> 24h0m0s)       </span>--upload-certs                         上传 control-plane 证书到 kubeadm-certs Secret.</pre> </div> <p>　　本方案我们使用如下命令参数来初始化主控节点：</p> <div class="cnblogs_code"> <pre><span style="color: rgba(0, 0, 0, 1)">kubeadm init \       </span>--apiserver-advertise-address=<span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">0.10</span><span style="color: rgba(0, 0, 0, 1)"> \       </span>--control-plane-endpoint=<span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">0.10</span><span style="color: rgba(0, 0, 0, 1)">        \ </span>      --service-cidr=<span style="color: rgba(128, 0, 128, 1)">10.96</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span>/<span style="color: rgba(128, 0, 128, 1)">16</span><span style="color: rgba(0, 0, 0, 1)"> \       </span>--pod-network-cidr=<span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span>/<span style="color: rgba(128, 0, 128, 1)">16</span></pre> </div> <p>　　执行以上命令，init 预检查到我的机器CUP和内存不满足性能要求，提示如下：此时需要关闭虚拟机，重新调整CPU核心数和内存大小。</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/e2971c654371b5c74b98821ddb45783c.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>继续运行命令，发现提示 "  It seems like the kubelet isn't running or healthy. "，的错误，表示kubelet未能正常运行，通过查看kubelet的运行日志发现报错如下：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/63e6b5f9d338724bb131bcb783ae4ec8.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>意思是因为kubelet cgroup驱动程序“systemd”与docker cgroup驱动程序“cgroupfs”不同，所以我们需要调整为相同。调整方式为修改docker cgroup的驱动程序为systemd(官方推荐用systemd)，编辑/etc/docker/daemon.json文件，修改或增加  "exec-opts":["native.cgroupdriver=systemd"] 代码：</p> <div class="cnblogs_code"> <pre><span style="color: rgba(0, 0, 0, 1)">{   </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">registry-mirrors</span><span style="color: rgba(128, 0, 0, 1)">"</span>: [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">https://yyipnm7g.mirror.aliyuncs.com</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">],   </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">exec-opts</span><span style="color: rgba(128, 0, 0, 1)">"</span>:[<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">native.cgroupdriver=systemd</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]    }</span></pre> </div> <p> 重启机器再次运行init命令（如果运行失败，提示某些端口被占用和某些文件已经存在，需要使用"  kubeadm reset  "重置后再运行）后，这可能会需要几分钟来完成组件的安装，安装成功后应该看到类似如下的输出：</p> <p>　<img decoding="async" src="http://img.555519.xyz/uploads3/20220501/987667ecf503390429b2888df43d29de.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>屏幕输出中提示：</p> <p>　　◉你的Kubernetes控制飞机已成功初始化。</p> <p>　　◉要开始使用群集，您需要以普通用户身份运行以下操作：</p> <div class="cnblogs_code"> <pre>  mkdir -p $HOME/<span style="color: rgba(0, 0, 0, 1)">.kube   sudo cp </span>-i /etc/kubernetes/admin.conf $HOME/.kube/<span style="color: rgba(0, 0, 0, 1)">config   sudo chown $(id </span>-u):$(id -g) $HOME/.kube/config</pre> </div> <p>或者如果你是root用户，可以运行：</p> <div class="cnblogs_code"> <pre>  export KUBECONFIG=/etc/kubernetes/admin.conf</pre> </div> <p>　　◉您应该在集群上部署一个pod网络，使用下列选项之一运行kubectl apply -f [podnetwork].yaml：</p> <div class="cnblogs_code"> <pre> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">kubernetes.io/docs/concepts/cluster-administration/addons/</span></pre> </div> <p>选项提供了一个地址，这个地址包含了很多的网络插件，如图：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/e294ecc628643a8183b4c1ed168b7b18.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p> 此处本人使用Calico插件，点击选项可能无法访问网址，无法下载其对应的yaml文件。使用如下命令下载yaml文件：</p> <div class="cnblogs_code"> <pre>curl https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">docs.projectcalico.org/manifests/calico.yaml -O</span></pre> </div> <p>如果无法直接在Linux中下载，可以直接访问https://docs.projectcalico.org/manifests/calico.yaml下载后上传到主机。然后再使用命令：</p> <div class="cnblogs_code"> <pre>kubectl apply -f calico.yaml</pre> </div> <p>创建POD网络，如图所示，表示POD网络创建完成：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/98a95add7cc423d3e6a81a05ec7ae8db.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>等待一段时间使用 "  kubectl get nodes  "查看节点状态，节点将由NotReady--&gt;Ready，如图：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/fafe07d1b8d24993da4b6d743f90af98.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p>　　◉通过在每个节点上复制证书颁发机构和服务帐户密钥，然后以root用户身份运行以下操作，可以加入任意数量的控制平面节点：</p> <div class="cnblogs_code"> <pre> kubeadm join <span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">0.10</span>:<span style="color: rgba(128, 0, 128, 1)">6443</span> --<span style="color: rgba(0, 0, 0, 1)">token zh274u.866t6kyo6cpxv40f \         </span>--discovery-token-ca-cert-<span style="color: rgba(0, 0, 0, 1)">hash sha256:c87e21c58a669984cd9ae2bd46ba34976584d88948b2445a378b9b6b734641c8 \         </span>--control-plane </pre> </div> <p>　　◉通过root用户身份在每个节点上运行以下操作，可以加入任意数量的工作节点：</p> <div class="cnblogs_code"> <pre>kubeadm join <span style="color: rgba(128, 0, 128, 1)">192.168</span>.<span style="color: rgba(128, 0, 128, 1)">0.10</span>:<span style="color: rgba(128, 0, 128, 1)">6443</span> --<span style="color: rgba(0, 0, 0, 1)">token zh274u.866t6kyo6cpxv40f \         </span>--discovery-token-ca-cert-hash sha256:c87e21c58a669984cd9ae2bd46ba34976584d88948b2445a378b9b6b734641c8 </pre> </div> <p> 根据这些提示完成提示操作后，集群环境就搭建完成了，init成功后的这些提示建议保存，方便后续增加主节点和工作节点。最终查看集群状态结果如下：</p> <p><img decoding="async" src="http://img.555519.xyz/uploads3/20220501/d103b679c3e69a0a87d4478fbadc0e86.jpg" alt="从零开始搭建高可用的k8s集群_在线工具"></p> <p><strong>三、在集群中部署应用</strong></p> <p>待续。。</p> <p> </p> 			                </div>
                <div class="clearfix"></div>
                <div class="col-md-12 mt-5">
                                        <p>上一个：<a href="/news/article-108303.htm">岜山中医药健康旅游基地(岜山中医药文化馆)</a></p>
                                        <p>下一个：<a href="/news/article-109119.htm">南平市宠物店在哪里（南平有宠物医院吗）</a></p>
                                    </div>
                                </div>
                <div class="col-md-3">
                    <div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">热门文章</h3>
    </div>
    <div class="panel-body">
        <ul class="p-0 x-0" style="list-style: none;margin: 0;padding: 0;">
                        <li class="py-2"><a href="/free-nodes/2025-4-20-free-v2ray.htm" title="V2ray免费VPN机场 | 4月20日18.9M/S|免费V2ray/SSR/Shadowrocket/Clash订阅节点地址分享">V2ray免费VPN机场 | 4月20日18.9M/S|免费V2ray/SSR/Shadowrocket/Clash订阅节点地址分享</a></li>
                        <li class="py-2"><a href="/news/article-92155.htm" title="宠物免费领养平台下载安装最新版大全（宠物领养网下载）">宠物免费领养平台下载安装最新版大全（宠物领养网下载）</a></li>
                        <li class="py-2"><a href="/news/article-93593.htm" title="vue组件间的传值，父传子，子传父，兄弟之间传值，跨级传值">vue组件间的传值，父传子，子传父，兄弟之间传值，跨级传值</a></li>
                        <li class="py-2"><a href="/news/article-99544.htm" title="动物医院资质要求标准（动物医院资质要求标准是多少）">动物医院资质要求标准（动物医院资质要求标准是多少）</a></li>
                        <li class="py-2"><a href="/news/article-90628.htm" title="动物疫苗接种时间表（动物 疫苗）">动物疫苗接种时间表（动物 疫苗）</a></li>
                        <li class="py-2"><a href="/news/article-109119.htm" title="南平市宠物店在哪里（南平有宠物医院吗）">南平市宠物店在哪里（南平有宠物医院吗）</a></li>
                        <li class="py-2"><a href="/news/article-87723.htm" title="开宠物店狗粮怎么进货呢（开宠物店狗粮怎么进货呢视频）">开宠物店狗粮怎么进货呢（开宠物店狗粮怎么进货呢视频）</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-4-2-clash-v2ray-ss-ssr.htm" title="V2ray免费VPN机场 | 4月2日19.1M/S|免费V2ray/SSR/Clash/Shadowrocket订阅节点地址分享">V2ray免费VPN机场 | 4月2日19.1M/S|免费V2ray/SSR/Clash/Shadowrocket订阅节点地址分享</a></li>
                        <li class="py-2"><a href="/news/article-86278.htm" title="宠物医院美团好评200字怎么写 宠物医院美团好评200字怎么写的">宠物医院美团好评200字怎么写 宠物医院美团好评200字怎么写的</a></li>
                        <li class="py-2"><a href="/free-nodes/2025-4-24-free-node-subscribe.htm" title="V2ray免费VPN机场 | 4月24日21.2M/S|免费V2ray/Clash/Shadowrocket/SSR订阅节点地址分享">V2ray免费VPN机场 | 4月24日21.2M/S|免费V2ray/Clash/Shadowrocket/SSR订阅节点地址分享</a></li>
                    </ul>
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">归纳</h3>
    </div>
    <div class="panel-body">
        <ul class="p-0 x-0" style="list-style: none;margin: 0;padding: 0;">
                        <li class="py-2">
                <h4><span class="badge" style="float: right;">6</span> <a href="/date/2025-05/" title="2025-05 归档">2025-05</a></h4>
            </li>
                        <li class="py-2">
                <h4><span class="badge" style="float: right;">89</span> <a href="/date/2025-04/" title="2025-04 归档">2025-04</a></h4>
            </li>
                    </ul>
    </div>
</div>

                </div>
            </div>
        </div> <!-- container -->
    </section>
    <!--====== ABOUT THREE PART ENDS ======-->
        <!--====== FOOTER PART START ======-->
    <footer id="footer" class="footer-area">
        <div class="footer-copyright">
            <div class="container">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="copyright text-center">
                                                <p>
                                                <a href="/">首页</a> |
                                                <a href="/free-nodes/">免费节点</a> |
                                                <a href="/paid-subscribe/">推荐机场</a> |
                                                <a href="/news/">新闻资讯</a> |
                                                <a href="/client.htm">客户端</a> |
                                                <a href="/about-us.htm">关于我们</a> |
                        <a href="/disclaimer.htm">免责申明</a> |
                        <a href="/privacy.htm">隐私申明</a> |
                        <a href="/sitemap.xml">网站地图</a>
                    </p>
                            <p class="text">V2ray免费机场 节点订阅中文官网 版权所有 Powered by WordPress</p>
                        </div> <!-- copyright -->
                    </div>
                </div> <!-- row -->
            </div> <!-- container -->
        </div> <!-- footer copyright -->
    </footer>
    <!--====== FOOTER PART ENDS ======-->
    <!--====== BACK TOP TOP PART START ======-->
    <a href="#" class="back-to-top"><i class="lni-chevron-up"></i></a>
    <!--====== BACK TOP TOP PART ENDS ======-->
    <!--====== jquery js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/vendor/modernizr-3.6.0.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/vendor/jquery-1.12.4.min.js"></script>
    <!--====== Bootstrap js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/bootstrap.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/popper.min.js"></script>
    <!--====== Images Loaded js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/imagesloaded.pkgd.min.js"></script>
    <!--====== Scrolling Nav js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/jquery.easing.min.js"></script>
    <script src="/assets/website/js/frontend/surfboardnode/scrolling-nav.js"></script>
    <!--====== Slick js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/slick.min.js"></script>
    <!--====== Main js ======-->
    <script src="/assets/website/js/frontend/surfboardnode/main.js"></script>
    <script src="https://www.freeclashnode.com/assets/js/frontend/invite-url.js"></script>
    <script src="/assets/website/js/frontend/G.js"></script>
</body>

</html>